package trade.axht.springcloud.provideruser.controller;

import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import trade.axht.springcloud.provideruser.entity.User;
import trade.axht.springcloud.provideruser.repository.UserRepository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 用户微服务Controller。
 *
 * @author hmilyylimh
 *
 * @version 0.0.1
 *
 * @date 2017/9/17
 *
 */
@RestController
public class MsSimpleProviderUserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("/simple/{id}")
    public User findById(@PathVariable Long id) {
        return this.userRepository.findOne(id);
    }

    @PostMapping("/user")
    public User postUser(@RequestBody User user){
        System.out.println("@GetMapping(\"user\")接收参数对象user:"+user);
        return user;
    }

    @GetMapping("listAll")
    public List<User> listAll(){
        ArrayList<User> list= Lists.newArrayList();
        User user1=new User();
        user1.setName("user1");

        User user2=new User();
        user2.setName("user2");

        User user3=new User();
        user3.setName("user3");

        User user4=new User();
        user4.setName("user4");

        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        return  list;
    }
}
